package com.leeon.container;

import java.util.ArrayList;

class Apple{

    private static int counter;
    private final long id = counter++;

    public long getId(){
        return id;
    }

}

class Gala extends Apple{}
class Fusi extends Apple{}
class Xiao extends Apple{}



class Orange{}

public class ApplesAndOrangesWithoutGenerics {
    public static void main(String[] args){
/*        ArrayList arrayList = new ArrayList();
        arrayList.add(new Apple());
        arrayList.add(new Orange());
        System.out.println("size " + arrayList.size());
        for(int i = 0 ; i < arrayList.size();i++){
            long id = ((Apple)arrayList.get(i)).getId();
            System.out.println("apple id : " + id);
        }*/
        //---限定类型
        /*
        ArrayList<Apple> apples = new ArrayList<Apple>();
        for(int i = 0; i < 3; i++){
            apples.add(new Apple());
        }
        for (int i = 0; i < apples.size(); i++){
            System.out.println("apple id = " + ((Apple)apples.get(i)).getId());
        }
        for (Apple a : apples) {
            System.out.println("for each apple id = " + a.getId());
        }*/
        //---向上转型
        ArrayList<Apple> apples = new ArrayList<Apple>();
        apples.add(new Fusi());
        apples.add(new Xiao());
        apples.add(new Gala());

        for (Apple a: apples) {
            System.out.println("apple a " + a);
        }

    }

}
